Unable to `submit()` an html form after intercepting the submit with javascript.
Posted
by Ross Rogers
on Stack Overflow
See other posts from Stack Overflow
or by Ross Rogers
Published on 2010-04-27T04:46:47Z
Indexed on
2010/04/27
4:53 UTC
Read the original article
Hit count: 158
JavaScript
I'm trying to intercept the submission of a form in order to change the value of my keywords
label.
I have the following code:
<HTML>
<FORM name="searchForm" method="get" action="tmp.html" >
<input type="label" name="keywords" />
<input type="button" name="submit" value="submit" onclick="formIntercept();"/>
</FORM>
<SCRIPT language="JavaScript">
document.searchForm.keywords.focus();
function formIntercept( ) {
var f = document.forms['searchForm'];
f.keywords.value = 'boo';
f.submit();
};
</SCRIPT>
</HTML>
When I run this in chrome and click the submit button the keywords label changes to boo
, but the javascript console says:
Uncaught TypeError: Property 'submit' of object <#an HtmlFormElement> is not a function.
How can I submit the form with the manipulated keywords?
© Stack Overflow or respective owner